//
// Copyright (C) [2024] Xingyun Integrated Circuit Co., Ltd.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//
#include "TopLevelResourcesGPGPU.h"

#include "ArchInfoGPGPU.h"
#include "Config.h"
#include "InstructionGPGPU.h"
#include "Log.h"
#include "ObjectRegistry.h"
#include "Operand.h"
#include "OperandGPGPU.h"
#include "PteAttributeGPGPU.h"
#include "PyEnvironmentGPGPU.h"
#include "RegisterGPGPU.h"
#include "RetOperandGPGPU.h"

using namespace std;

namespace Green {

  /*!
    Top level resources should implement Initialize and Destroy interface methods.

    The method calling order (in terms of modules involved) in initialize_top_level_resources() and destroy_top_level_resources() should be in opsite order.

    The base level initialize_top_level_resources should be called first and the destroy_top_level_resources should be called last
  */

  void initialize_top_level_resources_GPGPU(int argc, char* argv[])
  {
    vector<ArchInfo*> arch_info_objs;
    arch_info_objs.push_back(new ArchInfoGPGPU("RiscV"));

    // The architecture-level Python modules must be initialized prior to calling the base
    // initialize_top_level_resources() function
    PyEnvironmentGPGPU::initialize_python_modules();

    initialize_top_level_resources(argc, argv, arch_info_objs);

    // Register various GPGPU objects.
    ObjectRegistry* obj_registry = ObjectRegistry::Instance();

    // Register Operand based objects.
    obj_registry->RegisterObject(new VsetvlAvlImmediateOperand());
    obj_registry->RegisterObject(new VsetvlVtypeImmediateOperand());
    obj_registry->RegisterObject(new VectorMaskOperand());
    obj_registry->RegisterObject(new BaseOffsetBranchOperand());
    obj_registry->RegisterObject(new RetOperand());
    obj_registry->RegisterObject(new ConditionalBranchOperandGPGPU());
    obj_registry->RegisterObject(new CompressedConditionalBranchOperandGPGPU());
    obj_registry->RegisterObject(new CompressedRegisterOperandGPGPU());
    obj_registry->RegisterObject(new VsetvlAvlRegisterOperand());
    obj_registry->RegisterObject(new VsetvlVtypeRegisterOperand());
    obj_registry->RegisterObject(new VectorBaseOffsetLoadStoreOperandGPGPU());
    obj_registry->RegisterObject(new VectorStridedLoadStoreOperandGPGPU());
    obj_registry->RegisterObject(new VectorIndexedLoadStoreOperandGPGPU());
    obj_registry->RegisterObject(new MultiVectorRegisterOperandGPGPU());

    // Register Paging related objects.
    obj_registry->RegisterObject(new AddressPteAttributeGPGPU());
    obj_registry->RegisterObject(new DAPteAttributeGPGPU());
    obj_registry->RegisterObject(new GPteAttributeGPGPU());
    obj_registry->RegisterObject(new UPteAttributeGPGPU());
    obj_registry->RegisterObject(new XPteAttributeGPGPU());
    obj_registry->RegisterObject(new WRPteAttributeGPGPU());
    obj_registry->RegisterObject(new VPteAttributeGPGPU());

    // Register Instruction related objects.
    obj_registry->RegisterObject(new RetInstruction());
    obj_registry->RegisterObject(new VectorAMOInstructionGPGPU());
    obj_registry->RegisterObject(new VsetvlInstruction());
  }

  void destroy_top_level_resources_GPGPU()
  {
    destroy_top_level_resources();
  }

}
